<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle" class="LayoutBox">
        <div class="left">
          <el-select v-model="query.team" clearable size="small" filterable placeholder="选择团队名称搜索" class="filter-item" @change="crud.toQuery">
            <el-option v-for="item in team" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
          <el-select v-model="query.website" clearable size="small" filterable placeholder="选择网站名称搜索" class="filter-item" @change="crud.toQuery">
            <el-option v-for="item in website" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
          <el-select v-model="query.anchor" clearable size="small" filterable placeholder="选择主播昵称搜索" class="filter-item" @change="crud.toQuery">
            <el-option v-for="item in anchor" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
          <date-range-picker v-model="query.createTime" class="date-item" @change="crud.toQuery" />
        <!-- <rrOperation /> -->
        </div>
        <div class="right">
          <el-input v-model="query.name" clearable size="small" placeholder="输入关键词搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        </div>
      </div>
      <crudOperation :permission="permission" />
    </div>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :header-cell-style="{
        background:'#f5f7fa',color:'#000000'}"
      show-summary
      :summary-method="getSummaries"
      border
      :data="crud.data"
      style="width: 100%;"
      @sort-change="sortChange"
    >
      <el-table-column v-for="item in Tablelist" :key="item.id" :width="item.width" :sortable-name="item.sortableName" :align="item.align" :sortable="item.sortable" :show-overflow-tooltip="true" :prop="item.prop" :label="item.label" />
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>

<script>
import CRUD, { presenter, header, crud } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import DateRangePicker from '@/components/DateRangePicker'
import pagination from '@crud/Pagination'
import { Tablelist } from './ElTable'
import { mapGetters } from 'vuex'

export default {
  name: 'DayDataIndex',
  components: { crudOperation, DateRangePicker, pagination },

  cruds() {
    return CRUD({ url: 'api/jobs', optShow: {
      add: false,
      edit: false,
      del: false,
      reset: false
    }},
    )
  },
  mixins: [presenter(), header(), crud()],

  data() {
    return {
      Tablelist,
      delLoading: false,
      // 按钮权限
      permission: {

      }
    }
  },
  computed: {
    ...mapGetters(['team', 'anchor', 'website'])
  },
  created() {
  },
  methods: {
    // 后台排序
    sortChange(data) {
      const { prop, order } = data
      if (!order) { this.query[prop] = undefined } else this.query[prop] = order === 'ascending' ? 'asc' : 'desc'
      this.crud.toQuery()
      this.query[prop] = undefined
    },
    // 总计
    getSummaries(param) {
      const { columns } = param
      const sums = []
      columns.forEach((column, index) => {
        // index 第几列从0开始
        if (index === 0) {
          sums[0] = '总计'
          return
        }
        if (index === 1) {
          // this.customNum 自定义值一般为后台返回合计值
          sums[1] = this.customNum
          return
        }
        sums[index] = ''
      })
      return sums
    }

  }
}
</script>

<style lang="scss" scoped>

</style>
